
cd "$data"

use "data1.dta", clear


forval i=1/4 {
rename pid`i' pid_`i' 
}	

forval i=6/21 {
rename pid`i' pid_`i' 
}	

	
keep Labourind_strength* pid_* leftRightW* wave* lrLabW* lrConW* redistConW* strength* refvotecat* id leftright* EUIntegrationSelfW* EUIntegrationLabW* redistSelfW* redistLabW* immigcultural* immigeconomic* LR_Corbynw* Labourlike* Conlike* labUnitedW* conUnitedW*




gen Labourpid6= 1 if pid_6==2
gen pid6 = pid_6

gen Labourforce6 = Labourind_strength6 if Labourind_strength6!=0

gen consistentlabour_after = 1 if pid_6==2 & pid_7==2 & pid_8==2 & pid_9==2 & pid_10==2 & pid_11==2 & pid_12==2
gen consistentlabour_before = 1 if pid_1==2 & pid_2==2 & pid_3==2 & pid_4==2 & pid_6==2 

gen brexitnochange = .
replace brexitnochange = 1 if refvotecat6==1 & refvotecat7==1 & refvotecat8==1 & refvotecat9==1 & refvotecat10==1 & refvotecat11==1 & refvotecat12==1 // leave
replace brexitnochange = 1 if refvotecat6==0 & refvotecat7==0 & refvotecat8==0 & refvotecat9==0 & refvotecat10==0 & refvotecat11==0 & refvotecat12==0 // remain

drop if id==.
	
reshape long Labourind_strength pid_ leftRightW  wave lrLabW extremity lrConW strength refvotecat leftright EUIntegrationSelfW redistSelfW immigcultural immigeconomic EUIntegrationLabW redistLabW LR_Corbynw Labourlike Conlike labUnitedW conUnitedW, i(id) j(vague)
	

	gen partyid= . 							
	replace partyid = 1 if pid6==2	// labour pid
	replace partyid = 2 if pid6==1 // consevative pid
	replace partyid = 0 if pid6==0	// independents
	replace partyid = 3 if pid6==3 | pid6==4 | pid6==5 // other pid 
		
		*lab define partyid 0"independent" 1"labour" 2"con" 3"other"
		label values partyid partyid
	
	gen partyid_dynamic= . 							
	replace partyid_dynamic = 1 if pid_==2	// labour pid
	replace partyid_dynamic = 2 if pid_==1 // consevative pid
	replace partyid_dynamic = 0 if pid_==0	// lindependents
	replace partyid_dynamic = 3 if pid_==3 | pid_==4 | pid_==5 // other pid 
		
	label values partyid partyid_dynamic
		
		
		
lab define wavedates 1 "Feb/Mar'14" 2 "May/Jun'14" 3 "Sept/Oct'14" 4 "Mar'15" 5 "Apr/May'15" 6 "May '15" ///
7 "Apr/May'16" 8 "May/Jun'16" 9 "Jun/Jul'16" 10 "Nov/Dec'16" 11 "Apr/May'17" 12 "May/Jun'17" 13 "Jun'17" ///
14 "May '18" 15"Mar/May'19" 16"May/Jun'19" 17"Nov'19" 18"Nov/Dec'19" 19"Dec'19" 20"Jun'20" 21"May'21" 22"Nov/Dec'21" 23"May'22"
	
		label values vague wavedates 		
	
	save "panel.dta", replace // this data is for panel data analysis. 
	